#include "HandshakeTaskQueue.h"

#include <condition_variable>

namespace droneswarm
{

    HandshakeTaskQueue::HandshakeTaskQueue() {}
    HandshakeTaskQueue::~HandshakeTaskQueue() {}

    void HandshakeTaskQueue::addTask( HandshakeTask &task )
    {
        mutex_.lock();
        TaskQueue_.push( task );
        mutex_.unlock();
    }
    void HandshakeTaskQueue::addTask( std::function< void( std::any ) > func, std::any arg )
    {

        HandshakeTask task;
        task.function = func;
        task.arg = arg;
        mutex_.lock();
        TaskQueue_.push( task );
        // cv_.notify_one();
        mutex_.unlock();
    }

    //
    HandshakeTask HandshakeTaskQueue::takeTask()
    {
        HandshakeTask ht;
        mutex_.lock();
        if ( TaskQueue_.size() > 0 )
        {
            ht = TaskQueue_.front();
            TaskQueue_.pop();
        }
        mutex_.unlock();
        return ht;
    }
}  // namespace droneswarm